package com.dnzx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.dnzx.framework.page.PageResult;
import org.springframework.stereotype.Service;

import com.dnzx.dao.IArticleDao;
import com.dnzx.model.ArticleBO;
import com.dnzx.service.IArticleService;

/**
 * 文章管理
 */
@Service
public class ArticleServiceImpl implements IArticleService {

    @Resource
    private IArticleDao articleDao;

    @Override
    public void save(ArticleBO articleBO) throws Exception {
        this.articleDao.save(articleBO);
    }

    @Override
    public void delete(Long id) throws Exception {
        this.articleDao.delete(id);
    }

    @Override
    public void update(ArticleBO articleBO) throws Exception {
        this.articleDao.update(articleBO);
    }

    @Override
    public ArticleBO get(Long id) {
        return this.articleDao.get(id);
    }

    @Override
	public ArticleBO get(ArticleBO articleBO) {
    	List<ArticleBO> articleBOList = this.queryList(articleBO);
    	if (articleBOList != null && articleBOList.size() > 0) {
    		return articleBOList.get(0);
    	}
		return null;
	}

    @Override
    public List<ArticleBO> queryList(ArticleBO articleBO) {
        return this.articleDao.queryList(articleBO);
    }

    @Override
    public PageResult<List<ArticleBO>> queryPage(ArticleBO articleBO, PageResult<List<ArticleBO>> pageResult) {
    	int totalRows = this.articleDao.queryCount(articleBO);
    	if (totalRows > 0) {
    		pageResult.setTotalRows(totalRows);
            pageResult.setCurrentPage(articleBO.getCurrentPage());
            pageResult.setPageSize(articleBO.getPageSize());
    		List<ArticleBO> records = this.articleDao.queryPage(pageResult.getPageSize(), pageResult.getStartRow(), articleBO);
    		pageResult.setT(records);
    	}
		return pageResult;
    }

}
